<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <script src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.1.1/jquery.min.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>

    <style>
        .form-horizontal{
            margin-top: 20%;
            margin-left: 30%;
        }

        .go-register{
            margin-left: 400px;
        }
    </style>

    <script>
        function login(){
            event.preventDefault();

            if(document.getElementById("inputEmail3").value=="" || document.getElementById("inputEmail3").value==null){
                document.getElementById("raccount").textContent="账号不能为空";
                return;
            }else if(document.getElementById("inputPassword3").value=="" || document.getElementById("inputPassword3").value==null){
                document.getElementById("rpassword").textContent="密码不能为空";
                return;
            }

            $.ajax({
                url:"user/login",
                data:{
                    account:document.getElementById("inputEmail3").value,
                    password:document.getElementById("inputPassword3").value
                },
                type:"GET",
                dataType:"text",
                // contentType:"application/json;charset=utf-8",
                success:function (res){
                    if(res=="X"){
                        alert("您还没有注册，请注册！")
                    }else if(res=="Y"){
                        window.location.href="./show.html"
                    }else if(res=="N"){
                        alert("账号或密码错误")
                    }
                },
                complete:function (err) {
                    console.log(err)
                }
            })
        }
    </script>
</head>
<body>
<form class="form-horizontal">
    <div class="form-group">
        <label for="inputEmail3" class="col-sm-2 control-label">账号</label>
        <div class="col-xs-4">
            <input type="text" class="form-control" id="inputEmail3" placeholder="账号"><font style="color: red" id="raccount">*必填</font>
        </div>
    </div>

    <div class="form-group">
        <label for="inputPassword3" class="col-sm-2 control-label">密码</label>
        <div class="col-xs-4">
            <input type="password" class="form-control" id="inputPassword3" placeholder="密码"><font style="color: red" id="rpassword">*必填</font>
        </div>
    </div>

    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-default btn-primary" onclick="login(event)">登录</button>&nbsp;&nbsp;&nbsp;&nbsp;
            <button type="reset" class="btn btn-default btn-danger">重置</button>
        </div>
    </div>

    <div class="go-register">
        <a href="./register.html">没有账号？去注册~</a>
    </div>

</form>

</body>
</html>